티스토리 뷰
기본적으로 사용할 수 있는 Scalar 타입은 정해져있다.
//http://webonyx.github.io/graphql-php/type-definitions/scalars/
use GraphQL\Type\Definition\Type;
// Built-in Scalar types:
Type::string(); // String type
Type::int(); // Int type
Type::float(); // Float type
Type::boolean(); // Boolean type
Type::id(); // ID type
그 외에 필요한 타입은 커스텀하여 사용하여야하는데, 대표적으로 Date, DateTime 타입이 없는지 아쉬운 부분이다.
그래도 친절하게 필요한 타입을 정의하여 사용할 수 있도록 되어있어서 다행이다.
자세한 내용은 아래를 참고해서 추가하면된다.
http://webonyx.github.io/graphql-php/type-definitions/scalars/
<?php
use GraphQL\Language\Parser;
use GraphQL\Utils\BuildSchema;
use GraphQL\Utils\AST;
$cacheFilename = 'cached_schema.php';
if (!file_exists($cacheFilename)) {
$document = Parser::parse(file_get_contents('./schema.graphql'));
file_put_contents($cacheFilename, "<?php\nreturn " . var_export(AST::toArray($document), true) . ";\n");
} else {
$document = AST::fromArray(require $cacheFilename); // fromArray() is a lazy operation as well
}
$typeConfigDecorator = function () {
if ($typeConfig['name'] === 'Date') {
$typeConfig = array_merge($typeConfig, [
'serialize' => function($value) {
if (! $value instanceof DateTimeImmutable) {
$value = new DateTime($value);
}
return $value->format('Y-m-d');
},
'parseValue' => function($value) {
return DateTimeImmutable::createFromFormat('YYYY-MM-DD', $value) ?: null;
},
'parseLiteral' => function($ast) {
if ($ast instanceof StringValueNode) {
return $ast->value;
} elseif (isset($ast->value)) {
return $ast->value;
}
return null;
}
]);
};
$schema = BuildSchema::build($document, $typeConfigDecorator);
...
댓글
- Total
- Today
- Yesterday
TAG
- addMonth
- 라라벨
- addMonthWithoutOverflow
- composite-primarykey
- session+token authorize
- composer-self-update
- 테스트_다중트랜잭션
- composer-install
- 메일
- Laravel
- php
- eloquant
- laravel-test
- graphql-php
- graphql
- 둘이상인증한번에사용하기
- exception-test
- redis
- Python
- MySQL
- POP3
- 정규식
- php-laravel
- 나는욕심쟁이
- 정의
- VIM-COMMAND
- django
- 자바스크립트
- php-composer
- vim
공지사항